﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RTGS.Library.Entities.Rtgs;
using RTGS.Library.DataAccess.Rtgs;
using System.Configuration;
using RTGS.Web;
using System.Data;
using RTGS.Library.Report;

public partial class form_rtgs_record_detail_o_clearing_form : BasePage
{
    private trntRepo trntrepo = new trntRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);

    private stpRecordDetailORepo roleDal = new stpRecordDetailORepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
    ReportSptDetailRecordO reportDal = new ReportSptDetailRecordO(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
    private string id = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
         try
          {
            List<trnt> listtrnt = trntrepo.GetList();
            foreach (var item in listtrnt)
            {
                ddlTrn.Items.Add(new ListItem(item.trn.Trim(), item.trndesc.Trim()));
            }

            ddlTrn.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));

            DataTable dt = reportDal.GetMember();

            ddlDebitParticipant.Items.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                ddlDebitParticipant.Items.Add(new ListItem(dr["accnbr"].ToString().Trim(), dr["memcde"].ToString().Trim()));
            }

            ddlDebitParticipant.Items.Insert(0, new ListItem("---pilih data--", string.Empty));

            ddlCreditParticipant.Items.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                ddlCreditParticipant.Items.Add(new ListItem(dr["accnbr"].ToString().Trim(), dr["memcde"].ToString().Trim()));
            }

            ddlCreditParticipant.Items.Insert(0, new ListItem("---pilih data--", string.Empty));

            if (ddlDebitParticipant.Items.Count > 0)
            {
                for (int i = 0; i < ddlDebitParticipant.Items.Count; i++)
                {
                    if (ddlDebitParticipant.Items[i].Value.ToString().Trim() == "BKCHIDJA")
                    {
                        ddlDebitParticipant.Items.FindByValue("BKCHIDJA").Selected = true;
                        break;

                    }
                }
            }

            if (ddlCreditParticipant.Items.Count > 0)
            {
                for (int i = 0; i < ddlCreditParticipant.Items.Count; i++)
                {
                    if (ddlCreditParticipant.Items[i].Value.ToString().Trim() == "SKNAIDJ1")
                    {

                        ddlCreditParticipant.Items.FindByValue("SKNAIDJ1").Selected = true;
                        break;
                    }
                }
            }

            txtDebitParticipant.Text = "BKCHIDJA";
            txtCreditParticipant.Text = "SKNAIDJ1";

            if (Context.Request.Params["isclearing"] != null)
            {
                if (Context.Request.Params["isclearing"] == "prefundkredit")
                    ddlTransTypeCode.Items.FindByValue("300").Selected = true;

                if (Context.Request.Params["isclearing"] == "prefunddebit")
                    ddlTransTypeCode.Items.FindByValue("310").Selected = true;

                if (Context.Request.Params["isclearing"] == "topprefundkredit1")
                    ddlTransTypeCode.Items.FindByValue("301").Selected = true;

                if (Context.Request.Params["isclearing"] == "topprefundkredit2")
                    ddlTransTypeCode.Items.FindByValue("302").Selected = true;

                if (Context.Request.Params["isclearing"] == "topprefunddebit")
                    ddlTransTypeCode.Items.FindByValue("311").Selected = true;

            }

            if (Request.Params["Id"] != null)
            {
                id = HttpUtility.HtmlEncode(Convert.ToString(Request.Params["Id"]));
            }

            if (id.Trim().Length > 0) // Edit an existing item
            {
                stpRecordDetailO obj = roleDal.GetById(id);
                if (obj != null)
                {
                    hfID.Value = id.ToString();
                    if (obj.recordDetailOtrTrn != "")
                    {
                        ddlTrn.Items.FindByText(obj.recordDetailOtrTrn).Selected = true;
                        trnt data = trntrepo.GetById(obj.recordDetailOtrTrn);
                        txtTrnDesc.Text = data.trndesc;
                    }

                    //group amount
                    if(obj.recordDetailOtrAmount!=null && obj.recordDetailOtrAmount!="")
                        txtAmount.Text = Convert.ToDecimal(obj.recordDetailOtrAmount).ToString("#,###.00");
                    txtBussinesDay.Text = obj.recordDetailOtrValuedate;

                    //group priority
                    txtPriority.Text = obj.recordDetailOrecordPriority;

                    //group detail
                    if (obj.recordDetailOtrTransactioncode != null && obj.recordDetailOtrTransactioncode != "")
                        ddlTransTypeCode.Items.FindByValue(obj.recordDetailOtrTransactioncode).Selected = true;

                    if (obj.recordDetailOtrFrommember != null && obj.recordDetailOtrFrommember != "")
                        ddlDebitParticipant.Items.FindByValue(obj.recordDetailOtrFrommember.Trim()).Selected = true;

                    if (obj.recordDetailOtrTomember != null && obj.recordDetailOtrTomember != "")
                        ddlCreditParticipant.Items.FindByValue(obj.recordDetailOtrTomember.Trim()).Selected = true;

                    txtDebitParticipant.Text = obj.recordDetailOtrFrommember;
                    txtCreditParticipant.Text = obj.recordDetailOtrTomember;
                }
            }
          }
         catch (Exception ex)
         {
         }

        }

    }
}